package com.lidx.back.statistics.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sun.tools.tree.ThisExpression;

import com.lidx.back.statistics.dao.ISystemVersionDao;
import com.lidx.back.statistics.entity.SystemVersionConfig;
import com.lidx.back.statistics.rest.VersionBean;
@Repository
public class SystemVersionDaoImpl implements ISystemVersionDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	public SystemVersionConfig getConfig(VersionBean versionBean) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from SystemVersionConfig where versionType=:vType and versionNum = :vNum")
				.setString("vType", versionBean.getVersionType())
				.setString("vNum", versionBean.getVersionNumber());
		List list = query.list();
		if(list.size()>0)
			return (SystemVersionConfig) list.get(0);
		return null;
	}

	public String getLatestVersionNum(String versionType) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("select distinct latestVersionNum from SystemVersionConfig where versionType=:vType")
				.setString("vType", versionType);
		return (String) query.uniqueResult();
	}

}
